import Vue from 'vue'
import Router from 'vue-router'
import {routerList} from "@/core/router/router_const";

Vue.use(Router);

export function resetRouter() {
    const newRouter = createRouter();
    (router as any).matcher = (newRouter as any).matcher // reset router
}

const createRouter = () => new Router({
    mode: 'history',
    scrollBehavior: (to, from, savedPosition) => {
        if (savedPosition) {
            return savedPosition
        } else {
            return {x: 0, y: 0}
        }
    },
    base: process.env.BASE_URL,
    routes: routerList.concat(routerList)
});

/**
 * 创建路由
 */
const router = createRouter();

export default router
